package cn.dlx.blog.dao;

import cn.dlx.blog.model.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserDao {
    String TABLE_NAEM = " user ";
    String INSERT_FIELDS = " name, password, salt, head_url, role ";
    String SELECT_FIELDS = " id, " + INSERT_FIELDS;
    @Insert({"insert into", TABLE_NAEM, "(", INSERT_FIELDS, ") values (#{name}, #{password}, #{salt}, #{headUrl}, #{role})"})
    void insertUser(User user);

    @Select({"select",SELECT_FIELDS,"from",TABLE_NAEM,"where id=#{id}"})
    User selectByID(int id);

    @Select({"select",SELECT_FIELDS,"from",TABLE_NAEM,"where name=#{name}"})
    User selectByName(@Param("name") String name);

    @Delete({"delete from",TABLE_NAEM,"where id=#{id}"})
    void deleteById(int id);
}
